<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="yaodian100" uri="http://www.yaodian100.com/jsp/yaodian100" %>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ include file="/taglibs.jsp"%> 
<link rel="stylesheet" href="/css/jquery.tooltip.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/css/ui.jqgrid.css" />
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<script src="/js/jquery.tooltip.min.js" type="text/javascript"></script>
<script src="/js/grid.locale-en.js" type="text/javascript"></script>
<script src="/js/jquery.jqGrid.min.js" type="text/javascript" charset="UTF-8"></script>
<s:url var="supplierPops" value="/json/supplierPops.do"/>
<s:url var="brandPops" value="/json/brandPops.do"/>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
	<script language="javascript">
		var content;
		var qry_target = '01';
		$().ready( function() {
			if ( "" == "${productIdParam}" )
				$("#productIdParam").val("可以用逗号输入商品编号查询").attr("class","txt-gy");
			
			$("#productIdParam").focus(function(){
				if($("#productIdParam").val()=='可以用逗号输入商品编号查询')
					$("#productIdParam").val("").removeClass("txt-gy");
			}).blur(function(){
				if($("#productIdParam").val()=='')
					$("#productIdParam").val("可以用逗号输入商品编号查询").attr("class","txt-gy");
			});
			 
			//$("#productIdParam").numeric({allow:","});
			$("#supplierIdParam").numeric();
			$("#specId").numeric();
			$("#getSupplier").click(function() {
				//qry_target = 'member';
				doAR('${supplierPops}', 'dialog'); 
				openDialog('供应商搜寻',content, 550, 440);
			});	

			//$("#brandIdParam").numeric();
			$("#getBrand").click(function() {
				doAR('${brandPops}', 'dialog'); 
				openDialog('品牌搜寻',content, 550, 440);
			});	
					
			$("tr[id*='tdDesc_']").tooltip(); 
			$("#productForm").submit(function(){
				if ( 0 == $(":checkbox[name='prdtDelete']:checked").size() ){
					alert("请勾择要修改的商品");
					return false;
				} 
				if ( "" == $("#productAttributeA").val() && "" == $("#productAttributeB").val() ){
					alert("请选择销售状态");
					return false;
				}
				if( ""!=$("#productAttributeA").val()){
					$("#productAttributeB").val($("#productAttributeA").val());
				}
				return true;
			});
			//load default value
			if ( "" != "${categoryLevel1Param}"){ 
				$('#elementSelect').find('option').remove().end();
				$("#categorySelect option[value='${categoryLevel1Param}']").attr('selected', 'selected');  
				$.post("${midContextPath}/category/getProductCategory.do",{categoryid:"${categoryLevel1Param}"},elementSelectCallback,"json");
			}
			
			$("#categorySelect").change(function(){
				if ( "" != $(this).val()  ){
					$.ajax({
					    url: '${midContextPath}/category/getProductCategory.do',
					    type: 'post',
					    dataType: 'json',
					    data: {categoryid:$(this).val(), callback: 'elementSelectCallback'},
					    cache: false,
					    beforeSend: function(xhr) {
								$('#elementSelect').find('option').remove().end();
					    },
					    complete:function(){
					    },
					    success: function( strData ){
					    	elementSelectCallback(strData);
						}
					});
				}
			});		
			$("#selAll").click(function(){
				$(":input[id*=prodId_]").attr('checked',$("#selAll").attr('checked'));
			});
		});
		function elementSelectCallback(categories){
			$('#elementSelect').append($("<option></option>").attr("value","").text("--请选择--"));
			for( var i = 0 ; i < categories.length; i++ ){
					$('#elementSelect').append($("<option></option>").attr("value",categories[i].id).text(categories[i].name));
			}
			if ( "" != "${categoryLevel2Param}" )
				$("#elementSelect option[value='${categoryLevel2Param}']").attr('selected', 'selected');
		}	
		function replaceProductIdParam(){
			if($("#productIdParam").val()=='可以用逗号输入商品编号查询')
				$("#productIdParam").val("");
		}
	</script>
<h1>商品管理<br/>
<div class="f-link"><a href="add.do">新增商品</a></div>
</h1>
<s:actionerror />
<s:actionmessage />
<s:fielderror />
<br/>
<div class="data-form"><s:form action="list.do" method="post">
	<b>商品编号：</b>
	<input name="productIdParam" id="productIdParam" type="text" title="商品编号" size="40" value="${productIdParam}">
	<b>商品名称：</b>
	<input name="productNameParam" id="productNameParam" type="text" title="商品名称" size="80" value="${productNameParam}">
	<br/>	
	<b>商品型态：</b>
	<select name="productTypeParam" id="productTypeParam" title="商品型态">
		<option value="" ${empty productTypeParam ? 'selected': ''}>全部</option>
		<option value="0" ${productTypeParam=='0' ? 'selected': ''}>一般</option>
		<option value="1" ${productTypeParam=='1' ? 'selected': ''}>预购</option>
		<option value="2" ${productTypeParam=='2' ? 'selected': ''}>赠品</option>
		<option value="3" ${productTypeParam=='3' ? 'selected': ''}>配件</option>
		<option value="7" ${productTypeParam=='7' ? 'selected': ''}>限定立即购买商品</option>
	</select>
  <b>销售状态：</b> 
  <s:select name="productAttributeParam" list="attributeMenu.options" listKey="key"  headerKey="" headerValue="全部" listValue="value.name"/>
  <b>供应商编号：</b>
	<s:textfield name="supplierParam" id="supplierIdParam" maxlength="6"/>
	<img class="ui-icon ui-icon-search" src="/images/none.gif" style="height:16px; width:16px; position:relative; display:inline;" 
		id="getSupplier"/>  
	<b>品牌：</b>
	<s:textfield name="brandParam" id="brandIdParam"/>
	<img class="ui-icon ui-icon-search" src="/images/none.gif" style="height:16px; width:16px; position:relative; display:inline;" 
		id="getBrand"/> 
	
	<br/> 
	<b>主分类：</b>
	<select id="categorySelect" name="categoryLevel1Param">
			<option value="">--请选择--</option>
      	<c-rt:forEach items="${rootCategories}" var="category">
			<option value="${category.id}">${category.name}</option>
		</c-rt:forEach>
   </select>
   <select id="elementSelect" name="categoryLevel2Param">
   	<option value="">--请选择--</option>
   </select> 
   <b>采购模式：</b>
   <s:select id="scmParam" name="scmParam" list="isScmMenu.options" listKey="key" headerKey="" headerValue="全部" listValue="value.name"/>
   <b>资料来源：</b>
   <s:select id="dataSrcParam" name="dataSrcParam" list="dataSrcMenu.options" listKey="key" headerKey="" headerValue="全部" listValue="value.name"/>
   <b>供应商来源：</b>
   <select name="supplierChannel" id="supplierChannel" title="供应商来源">
	   <option value="" >全部</option>
	   <option value="D" ${supplierChannel=='D' ? 'selected': ''}>自营商</option>
	   <option value="A" ${supplierChannel=='A' ? 'selected': ''}>经代销商</option>
   </select>
   <b>允许COD付款：</b>
   <select name="canUseCodYN" id="canUseCodYN" title="允许COD付款">
	   <option value="" >全部</option>
	   <option value="Y" ${canUseCodYN=='Y' ? 'selected': ''}>是</option>
	   <option value="N" ${canUseCodYN=='N' ? 'selected': ''}>否</option>
   </select>
   <b>大材积商品：</b>
   <select name="largeVolumeProduct" id="largeVolumeProduct" title="大材积商品">
	   <option value="" >全部</option>
	   <option value="Y" ${largeVolumeProduct=='Y' ? 'selected': ''}>是</option>
	   <option value="N" ${largeVolumeProduct=='N' ? 'selected': ''}>否</option>
   </select></br>
   <b>主檔图类型：</b>
   <select name="productGraphicType" id="productGraphicType" title="主檔图类型">
	   <option value="" >全部</option>
	   <option value="R" ${productGraphicType=='R' ? 'selected': ''}>长形图</option>
	   <option value="S" ${productGraphicType=='S' ? 'selected': ''}>方形图</option>
   </select>
   <b>退换货条件：</b>
   <s:select id="returnRule" name="returnRule" list="returnRuleMenu.options" listKey="key"  listValue="value.name" headerKey="" headerValue="全部" />
   <b>规格料号：</b>
	<s:textfield name="specCodeParam" id="specCodeParam"/>
	<b>属性代码(仓库代码)：</b>
	<s:textfield name="specId" id="specId"/>
 	<input type="button" value="搜寻" onclick="replaceProductIdParam();this.form.submit();" />
</s:form>
</div>
<p></p>
<br/><br/><br/>
<s:form action="editProductAttribute.do" method="post" id="productForm">
<table class="tb-1" width="100%">
	<thead>
		<tr>
      <th><input type="checkbox" id="selAll"></th>
			<th>商品图</th>
			<th>商品编号</th>
			<th>商品名称</th>
			<th>商品成本</th>
			<th>厂商建议售价</th>
			<th>最后修改时间</th>
			<th>商品型态</th>
			<th>销售状态</th>
			<th>采购模式</th>
			<th>资料来源</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody>
		<s:select id="productAttributeA" list="attributeMenu.options" listKey="key"  listValue="value.name" headerKey="" headerValue="---请选择销售状态---"/>
		<input type="submit" value="批次修改"/>				 		 
		<yaodian100:pageutil link="list.do" pagerObj="${pager}" />
    <c-rt:forEach items="${products}" var="product" varStatus="rows_index">            
			<tr class="${rows_index.count % 2 == 0 ? 'bg-yl' : ''}" id="tdDesc_${rows_index.count}" title="${not empty rsmap ?rsmap[product.productId]:''}">
				<td><input name="prdtDelete" type="checkbox" id="prodId_${rows_index.count}" value="${product.productId}" /></td>
				<td>
					<yaodian100:productImg productId="${product.productId}" postfix="m75" />
				</td>
				<td><a href="${midContextPath}/product2/edit.do?productId=${product.productId}" />${product.productId}</a></td>
				<td>${product.productName}</td>
				<td><fmt:formatNumber value="${product.productCost}" pattern="#####0.00"/></td>
				<td><fmt:formatNumber value="${product.listPrice}" pattern="#####0.0"/></td>
				<td><fmt:formatDate value="${product.modifyDate}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
				<td>
					<c-rt:if test="${product.productType eq '0'}">一般</c-rt:if>
					<c-rt:if test="${product.productType eq '1'}">预购</c-rt:if>
					<c-rt:if test="${product.productType eq '2'}">赠品</c-rt:if>
					<c-rt:if test="${product.productType eq '3'}">配件</c-rt:if>
					<c-rt:if test="${product.productType eq '7'}">限定立即购买商品</c-rt:if>
				</td>
				<td>${attributeMenu.options[product.isDelete].name}</td>		
				<td>${isScmMenu.options[product.isScm].name}</td>
				<td>${dataSrcMenu.options[product.dataSrc].name}</td>
				<td>
					<a href="${midContextPath}/product2/edit.do?productId=${product.productId}">设置主檔</a>
					<c-rt:if test="${product.stepFlag ge 2}">
						<br/><a href="${midContextPath}/product2/spec.do?productId=${product.productId}">设置规格</a>
					</c-rt:if>
					<c-rt:if test="${product.stepFlag ge 3}">
						<br/><a href="${midContextPath}/image2/edit.do?productId=${product.productId}">设置图檔</a>
					</c-rt:if>
					<c-rt:if test="${product.stepFlag ge 4}">
						<br/><a href="${midContextPath}/shelf2/list.do?productId=${product.productId}">设置上下架</a>
					</c-rt:if>
				</td>		
			</tr>
		</c-rt:forEach>
	</tbody>
</table>
<br />
<s:select id="productAttributeB" name="productAttribute" list="attributeMenu.options" listKey="key"  listValue="value.name" headerKey="" headerValue="---请选择销售状态---"/>
<input type="submit" value="批次修改"/>
<yaodian100:pageutil link="list.do" pagerObj="${pager}" />
</s:form> 	